// page/API/share/share.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex:0,//默认选中第一个tab
    showChecked:false,//默认switch不选中
    withShareTicket: false,//默认转发不携带withShareTicket
    updateChecked:false,//更新转发属性
    imageList: ['../../../image/getShareInfo.png'],
    tabList:[
      {
        title:"转发基本设置"
      },
      {
        title: "wx.getShareInfo"
      },
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //默认隐藏转发按钮
    if(this.data.showChecked){
      
    }else{
      wx.hideShareMenu();
    }

    console.log('globalData:'+app.globalData);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    //console.log(res);
    if(res.from === 'button'){
      //来自页面内的转发按钮
      console.log(res.targret);
    }else{
      //res.from === 'menu'
	    console.log(res.target);//undefined 来自右上角转发菜单
    }
    return{
      title:"天宇无敌",
      path:"page/API/share/share",
      imageUrl:"../../../image/wechatHL.png"
    }
  },
  tabClick: function(e){
    //console.log(e);
    this.setData({
      activeIndex:e.currentTarget.id
    })
  },
  //是否显示转发按钮
  changeShowed: function(e){
    //console.log(e);
    this.setData({
      showChecked:!this.data.showChecked
    })
    if(this.data.showChecked){
      //显示转发按钮
      wx.showShareMenu({
        withShareTicket: this.data.withShareTicket,//是否使用带 shareTicket 的转发详情
        success: function (res) {
          console.log(res);
        },
        fail: function (res) {
          console.log(res);
        }
      });
    }else{
      //隐藏转发按钮
      wx.hideShareMenu();
    }
  },
  //改变是否有携带sharekTicket
  changeWithShareTicket: function (e) {
    this.setData({
      withShareTicket: !this.data.withShareTicket
    });
    console.log("withShareTicket:"+this.data.withShareTicket);
  },
  //更新转发属性
  changeUpdate: function(e){
    wx.updateShareMenu({
      withShareTicket: true,
      success: function(res) {
        console.log(res);
      },
      fail: function(res) {},
      complete: function(res) {},
    })
  },
})